class SystemController < ApplicationController
  def index
    show
    render :action => 'show'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :controller => '' }

  def show
    @system = System.find(:first)
  end

  # delete this after one is mage
  def new
    @system = System.find(:first)
    if @system
      flash[:notice] = 'System already exists.. editing'
      redirect_to :action => 'edit', :id => @system
    else
      @system = System.new
    end
  end

  def create
    @system = System.new(params[:system])
    if @system.save
      flash[:notice] = 'System was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    if (params[:id])
      @system = System.find(params[:id])
    else
      @system = System.find(:first)
    end
  end

  def update
    @system = System.find(params[:id])
    if @system.update_attributes(params[:system])
      flash[:notice] = 'System was successfully updated.'
      redirect_to :action => 'show', :id => @system
    else
      render :action => 'edit'
    end
  end

  # shouldnt be a way to destroy system
  def destroy
    System.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end
